What is View in SQL server? Give an example to create a View in SQL server.
What is View in SQL server? Give an example to create a View in SQL.
28224-Mar-2023
Updated on 24-Mar-2023
Home / DeveloperSection / Forums / What is View in SQL server? Give an example to create a View in SQL.
What is View in SQL server? Give an example to create a View in SQL server.
Krishnapriya Rajeev
29-Mar-2023In SQL Server, a View is a virtual table that is the result set of an SQL query. Views simplify queries and they also hide the complexity of joins and other operations. The values in a view table can only be obtained from the based table. We cannot modify the contents of a View.
They are also used to restrict access to certain columns or rows of a table and implements security mechanism. Its name must be unique.
Syntax:
Example to create a View in SQL Server:
In this example, we're creating a view called Emp that shows the Name and Empid of an employee. The view is based on the Employee table but only shows the Empid column and the Name column. Once the view is created, it can be used just like a regular table in SQL queries:
This query will return the the Empid and Name of employee whose Empid equals '"E01" Note that views are read-only, so you cannot modify the data in the view directly. If you want to modify the underlying data, you'll need to modify the source table(s) instead.